package com.ruoyi.web.controller.cert;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cert.domain.CertType;
import com.ruoyi.cert.service.ICertTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 证书类型Controller
 *
 * @author mxh
 * @date 2023-03-26
 */
@Api("证书类型")
@RestController
@RequestMapping("/cert/certType")
public class CertTypeController extends BaseController {
    @Autowired
    private ICertTypeService certTypeService;

    /**
     * 查询证书类型列表
     */
    @PreAuthorize("@ss.hasPermi('cert:certType:list')")
    @GetMapping("/list")
    @ApiOperation("查询证书类型列表")
    public TableDataInfo list(CertType certType) {
        certType.setDeptId(getDeptId());
        startPage();
        List<CertType> list = certTypeService.selectCertTypeList(certType);
        return getDataTable(list);
    }

    /**
     * 导出证书类型列表
     */
    @PreAuthorize("@ss.hasPermi('cert:certType:export')")
    @Log(title = "证书类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CertType certType) {
        certType.setDeptId(getDeptId());
        List<CertType> list = certTypeService.selectCertTypeList(certType);
        ExcelUtil<CertType> util = new ExcelUtil<CertType>(CertType. class);
        util.exportExcel(response, list, "证书类型数据");
    }

    /**
     * 获取证书类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('cert:certType:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取证书类型详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(certTypeService.selectCertTypeById(id));
    }

    /**
     * 新增证书类型
     */
    @PreAuthorize("@ss.hasPermi('cert:certType:add')")
    @Log(title = "证书类型", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增证书类型")
    public AjaxResult add(@RequestBody CertType certType) {
        certType.setDeptId(getDeptId());
        return toAjax(certTypeService.insertCertType(certType));
    }

    /**
     * 修改证书类型
     */
    @PreAuthorize("@ss.hasPermi('cert:certType:edit')")
    @Log(title = "证书类型", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改证书类型")
    public AjaxResult edit(@RequestBody CertType certType) {
        certType.setDeptId(getDeptId());
        return toAjax(certTypeService.updateCertType(certType));
    }

    /**
     * 删除证书类型
     */
    @PreAuthorize("@ss.hasPermi('cert:certType:remove')")
    @Log(title = "证书类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除证书类型")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(certTypeService.deleteCertTypeByIds(ids));
    }
}
